﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BarcodeLib;

namespace WypożyczalniaV1
{
    public partial class Print : Form
    {
        public Print(string conf)
        {
            InitializeComponent();
            this.zap = new Zapytania(conf);
        }
        private Zapytania zap;
        public void CreatEan8(string kodEan8)
        {
            Barcode barcode = new Barcode()
            {
                IncludeLabel = true,
                Alignment = AlignmentPositions.CENTER,
                Width = 300,
                Height = 100,
                RotateFlipType = RotateFlipType.RotateNoneFlipNone,
                BackColor = Color.White,
                ForeColor = Color.Black,
            };

            Image img = barcode.Encode(TYPE.EAN8, kodEan8);
            pictureBox1.Image = img;

        }
        public void opcjaDruku(int i, string kodEan8)
        {
            switch (i)
            {
                case 1:
                    //1 drukuje karte czytelnika
                    string zapytanie = "SELECT Imie, Nazwisko, PESEL, KodEan8 FROM czytelnicy WHERE kodEan8='"+ kodEan8 +"'";
                    string[] tablica = this.zap.tab(zapytanie, 4);
                    label1.Text = "Imię: " + tablica[0];
                    label2.Text = "Nazwisko: " +tablica[1];
                    label3.Text = "Pesel: " +tablica[2];
                    CreatEan8(tablica[3]);

                    break;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {

            PrintDocument tmpDoc = new PrintDocument();
            tmpDoc.PrintPage += new PrintPageEventHandler(Tmpdoc_Print);
            PrintPreviewDialog tmpPpd = new PrintPreviewDialog();
            tmpPpd.Document = tmpDoc;
            tmpPpd.ShowDialog();
        }
        private void Tmpdoc_Print(Object sender, PrintPageEventArgs e)
        {
            Bitmap bmp = new Bitmap(groupBox1.ClientRectangle.Width, groupBox1.ClientRectangle.Height);
            groupBox1.DrawToBitmap(bmp, groupBox1.ClientRectangle);
            e.Graphics.DrawImage(bmp, 0, 0);
        }
    }
}
